# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=mautrix-telegram
pkgver=0.8.2_git20200801
pkgrel=0
_commit="bc4610af045f46f62927845959760b7e26c75659"
pkgdesc="A Matrix-Telegram hybrid puppeting/relaybot bridge"
url="https://github.com/tulir/mautrix-telegram"
arch="noarch"
license="AGPL-3.0-or-later"
depends="python3 py3-aiohttp py3-mautrix py3-ruamel.yaml py3-magic py3-sqlalchemy py3-alembic py3-commonmark py3-telethon py3-telethon-session-sqlalchemy"
makedepends="py3-setuptools"
checkdepends="py3-pytest py3-pytest-runner py3-pytest-mock py3-pytest-asyncio"
install="$pkgname.pre-install $pkgname.post-upgrade"
subpackages="$pkgname-openrc"
source="https://github.com/tulir/mautrix-telegram/archive/$_commit/mautrix-telegram-$_commit.tar.gz
	mautrix-telegram.initd
	mautrix-telegram.confd
	default-log-dir.patch
	"
builddir="$srcdir/$pkgname-$_commit"

build() {
	python3 setup.py build
}

check() {
	pytest
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"

	# Remove installed tests
	local _site_packages=$(python3 -c "import site; print(site.getsitepackages()[0])")
	rm -r "$pkgdir/$_site_packages"/tests/

	install -Dm644 mautrix_telegram/example-config.yaml "$pkgdir"/etc/mautrix-telegram/example-config.yaml
	install -Dm755 "$srcdir"/mautrix-telegram.initd "$pkgdir"/etc/init.d/mautrix-telegram
	install -Dm644 "$srcdir"/mautrix-telegram.confd "$pkgdir"/etc/conf.d/mautrix-telegram

	mkdir -p "$pkgdir"/usr/share/mautrix-telegram
	mv \
		"$pkgdir"/usr/alembic \
		"$pkgdir"/usr/alembic.ini \
		"$pkgdir"/usr/share/mautrix-telegram/
}
sha512sums="4e1a61da924719a3f7fdada539c1b57c84660d8567a706a6039e79a284368d093acbd06e43bf77d1765299f2d3e301142783e5c7090fbae1229a342666f8946f  mautrix-telegram-bc4610af045f46f62927845959760b7e26c75659.tar.gz
394e50290a212e0f68a9b4d53dfa181df3cc0494f01c88d701db018bc1ec454f0f92fd56b750c6229ffaf0d1b6832f9f2177a3a1444b9a3b92d23ad3194b566c  mautrix-telegram.initd
7b3c15dd2d0671c4c777bcf4f2e905d9a0b639a54828313ac9db1a9793fde3d092e92f18aa896bff94b9a81db3df74b3de65661c6879cb648d36f5cec2437df0  mautrix-telegram.confd
7e75b46226c928f3aa64b13a3042eae7da164006b262f40ff5bbfdda9e91c80c2189a009735539d2349a638ad11c6ce0bf4bd93db12f485cb4906553283512c3  default-log-dir.patch"
